import {getEx} from "@/services/crud"
import moment from 'moment'
export function getOnlineState(tid){
    return new Promise((re,rej)=>{
        getEx('/state/online/' +tid).then(res=>{
            res.data?.result?.history?.forEach(h => {
                var begin = moment(h.begin)
                var end = moment(h.end)
                var dif = end.diff(begin,'minute')
                h.online_hours = (dif/60).toFixed(2)
                h.Begin = begin.format('MM-DD HH:mm:ss')
                h.End = end.format('MM-DD HH:mm:ss')
               
            });
            re(res)
        }).catch(err=>{
            rej(err)
        })
    })
}

export default{
    getOnlineState,
}